
public class demo2 {
    public ListNode reverseKGroup(ListNode head, int k) {
        ListNode cut=head;
        int n=0;
        while (cut!=null){
            n++;
            cut=cut.next;
        }
        if(k>n)return head;
        int sum=n/k;
        ListNode cur=head;
        ListNode node=new ListNode(0);
        ListNode ret=node;
        while (sum>0){
           int temp=k;
            while (temp>0){
                ListNode t=cur.next;
                cur.next=ret;
                ret=cur;
                cur=t;
                temp--;
            }
            sum--;
        }
        if (cur!=null)ret.next=cur;
        return node.next;
    }
}
